package com.example.notificationtest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button sendNotice = (Button) findViewById(R.id.send_notice);
        sendNotice.setOnClickListener((View.OnClickListener) this);

//        // 方法2
//        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        manager.cancel(1);
    }

    @Override
    public void onClick(View view){
        switch (view.getId()){
            Intent intent = new Intent(this,NotificationActivity.class);
            PendingIntent pi = PendingIntent.getActivity(this,0,intent,0);

            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new NotificationCompat.Builder(this)
                    .setContentTitle("This is content title")
                    .setContentText("This is content  text")
                    .setWhen(System.currentTimeMillis())
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                    .setContentIntent(pi)
                    .setAutoCancel(true)  // 方法1
                    .setSound(Uri.fromFite(newFite("/systen/media/audio/ringtones/Luna．ogg")))  // 播放音频
                    .setVibrate(new long[] {0,1000,1000,1000})  // 振动
                    .setLights(Color.GREEN,1000,1000)  // LED 灯
                    .setDefaults(NotificationCompat.DEFAULT_ALL)  // 设置为默认
                    .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.big_iamge)))
                    .setPriority(NotificationCompat.PRIORITY_MAX)   //重要程度
                    .build();
            manager.notify(1,notification);
            break;
        default:
            break;
        }
    }
}